package cn.echogo.demo.activity;

import cn.echogo.ipart.R;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

public class TabActivity extends FragmentActivity implements View.OnClickListener {
	
	Fragment newlyListFragment;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.demo_tabs);

		newlyListFragment = new NewlyListFragment();
		
		findViewById(R.id.btn1).setOnClickListener(this);
		findViewById(R.id.btn2).setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn1: {
			FragmentManager fm = getSupportFragmentManager();
			FragmentTransaction ft = fm.beginTransaction();
			ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
			ft.replace(R.id.contentArea, newlyListFragment);
			ft.commit();
		}
			break;
		case R.id.btn2: {
			FragmentManager fm = getSupportFragmentManager();
			FragmentTransaction ft = fm.beginTransaction();
			ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
			ft.replace(R.id.contentArea, new OnlineListFragment());
			ft.commit();
		}
			break;
		}
	}

	public static class NewlyListFragment extends Fragment {
		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
			Log.d("NewlyListFragment", "onCreateView");
			return inflater.inflate(R.layout.demo_tabs_a, null);
		}
		@Override
		public void onDestroyView() {
			Log.d("NewlyListFragment", "onDestroyView");
			super.onDestroyView();
		}
		@Override
		public void onCreate(Bundle savedInstanceState) {
			Log.d("NewlyListFragment", "onCreate");
			super.onCreate(savedInstanceState);
		}
		@Override
		public void onResume() {
			Log.d("NewlyListFragment", "onResume");
			super.onResume();
		}
		@Override
		public void onPause() {
			Log.d("NewlyListFragment", "onPause");
			super.onPause();
		}
		@Override
		public void onAttach(Activity activity) {
			Log.d("NewlyListFragment", "onAttach");
			super.onAttach(activity);
		}
		@Override
		public void onDetach() {
			Log.d("NewlyListFragment", "onDetach");
			super.onDetach();
		}
		@Override
		public void onDestroy() {
			Log.d("NewlyListFragment", "onDestroy");
			super.onDestroy();
		}
	}

	public static class OnlineListFragment extends Fragment {
		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
			return inflater.inflate(R.layout.demo_tabs_b, null);
		}
	}

}
